local skel = fk.CreateSkill {
  name = "emo__tanmei",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__tanmei"] = "探梅",
  [":emo__tanmei"] = "锁定技，每当你使用牌指定目标后，若其没有“梅”标记，令其获得此牌颜色的“梅”标记，其不能弃置此颜色的牌。当一名角色使用了与其“梅”标记颜色相同的牌时，你摸一张牌并移去其标记。",

  ["@emoPlum"] = "梅",
}

skel:addEffect(fk.TargetSpecified, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    local to = data.to
    return target == player and player:hasSkill(skel.name) and to and not to.dead and to:getMark("@emoPlum") == 0
  end,
  on_cost = function(self, event, target, player, data)
    event:setCostData(self, {tos = {data.to}})
    return true
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(data.to, "@emoPlum", data.card:getColorString())
  end,
})

skel:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target:getMark("@emoPlum") == data.card:getColorString()
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(target, "@emoPlum", 0)
    player:drawCards(1, skel.name)
  end,
})

skel:addEffect("prohibit", {
  prohibit_discard = function (self, player, card)
    return card:getColorString() == player:getMark("@emoPlum")
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  if table.every(player.room.alive_players, function (p)
    return not p:hasSkill(skel.name, true)
  end) then
    for _, p in ipairs(player.room.alive_players) do
      if p:getMark("@emoPlum") ~= 0 then
        player.room:setPlayerMark(p, "@emoPlum", 0)
      end
    end
  end
end)

return skel
